package Order.DAO;

import Order.Entity.Product;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class ProductDAO implements IRepository<Product> {

    public ProductDAO(EntityManager em) {
        this.em = em;
    }

    public Product merge(Product entity) {
        return em.merge(entity);
    }

    public Product persist(Product entity) {
        em.persist(entity);
        return entity;
    }

    public void remove(Product entity) {
        entity = em.merge(entity);
        em.remove(entity);
    }

    public Product FindById(Integer id) {
        Query query = em.createQuery("select m from Product m where m.id = " + id);
        return (Product) query.getSingleResult();
    }
    private EntityManager em;
}
